package com.project.petLossSystem.interceptor;

import com.project.petLossSystem.common.Constants;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * admin路径拦截器
 */
@Component
public class AdminLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(request.getSession().getAttribute("admin") == null){
            response.sendRedirect("/admin/login");
            return false;
        }else{
            // 刷新session时间
            request.getSession().setMaxInactiveInterval(Constants.ADMIN_SESSION_EXPIRE);
            return true;
        }
    }
}
